package com.initialize.gateway.controller;

import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2019/12/26
 * Time: 7:52 下午
 * Description:查询网关的路由信息
 */
@RestController
@RequestMapping("/route")
public class DynamicRouteController {

    private final RouteDefinitionLocator routeDefinitionLocator;

    public DynamicRouteController(RouteDefinitionLocator routeDefinitionLocator) {
        this.routeDefinitionLocator = routeDefinitionLocator;
    }

    //获取网关所有的路由信息
    @RequestMapping("/routes")
    public Flux<RouteDefinition> getRouteDefinitions() {
        NettyDataBufferFactory nettyDataBufferFactory;
        return routeDefinitionLocator.getRouteDefinitions();
    }
}